package com.example.calculator_backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

/**
 * @description: 跨域配置
 * @author: hdr
 * @PACKAGE_NAME: com.example.calculator_backend.config
 * @DATE: 2025/8/11
 */

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*") // Spring Boot 3.x 推荐的通配方式
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(false) // 你现在的贷款计算器用不到 Cookie，建议关掉
                .maxAge(3600);
    }
}
